From 23def34b96fb69cfe9ca3c8e8cee7c01383779ff Mon Sep 17 00:00:00 2001 From: Tobias Stoeckmann Date: Fri, 13 Oct 2017 18:32:52 +0200 Subject: [PATCH] babl: fix memory leaks on error paths The database-focused functions of babl-cache are prone to memory leaks when errors occur. Signed-off-by: Tobias Stoeckmann --- babl/babl-cache.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/babl/babl-cache.c b/babl/babl-cache.c index 13badc5..dcc76f4 100644 --- a/babl/babl-cache.c +++ b/babl/babl-cache.c @@ -170,10 +170,15 @@ void babl_store_db (void) char *tmpp = calloc(8000,1); FILE *dbfile; + if (!tmpp) + return; snprintf (tmpp, 8000, "%s~", fish_cache_path ()); dbfile = fopen (tmpp, "w"); if (!dbfile) + { + free (tmpp); return; + } fprintf (dbfile, "%s\n", cache_header ()); /* sort the list of fishes by usage, making next run more efficient - @@ -273,6 +278,7 @@ void babl_init_db (void) { fprintf (stderr, "%s:%i: loading of cache failed\n", __FUNCTION__, __LINE__); + free (contents); return; } @@ -315,6 +321,7 @@ void babl_init_db (void) Babl *conv = (void*)babl_db_find(babl_conversion_db(), &token[1]); if (!conv) { + free (contents); return; } else -- 2.30.2